﻿using System;

namespace Skywalker.Fluently
{
    public class Factory : IFactory
    {
        public static IFactory Default = new Factory();

        public T CreateBuilder<T>() where T:IBuilder, new()
        {
            return new T();
        }

        public T ExecuteBuilder<T>(T builder, Action<T> setup) where T:IBuilder
        {
            if (setup != null)
                setup(builder);

            return builder;
        }

        public T CreateAndExecuteBuilder<T>(Action<T> setup) where T:IBuilder, new()
        {
            var builder = CreateBuilder<T>();
            ExecuteBuilder(builder, setup);
            return builder;
        }

    }

}